package com.ss.android.newmedia;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.bytedance.article.b.JsonTransformer;
import com.bytedance.article.b.a.GsonDependManager;
import com.bytedance.article.b.a.m;
import com.bytedance.article.b.b.DependProvider;
import com.bytedance.article.common.a.MonitorHeaderInfoUtil;
import com.bytedance.common.plugin.faces.LiteConstants;
import com.bytedance.common.plugin.faces.LiteProxy;
import com.bytedance.common.plugin.framework.model.ProcessType;
import com.bytedance.common.plugin.framework.util.PluginUtil;
import com.bytedance.common.plugin.interfaces.alipay.IAliPay;
import com.bytedance.common.plugin.interfaces.pushmanager.HttpMonitorServerWorker;
import com.bytedance.common.plugin.interfaces.pushmanager.IMessageContext;
import com.bytedance.common.plugin.interfaces.pushmanager.MessageConstants;
import com.bytedance.common.plugin.interfaces.pushmanager.classhandle.PushClassLoader;
import com.bytedance.common.plugin.interfaces.pushmanager.classhandle.PushClassTest;
import com.bytedance.common.plugin.interfaces.pushmanager.client.OpenUrlReceiverUtil;
import com.bytedance.common.plugin.interfaces.pushmanager.client.SsPushManager;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.reflect.Reflect;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.bytedance.frameworks.baselib.network.http.AppConfig;
import com.bytedance.ttnet.b.HttpRequestInfo;
import com.squareup.picasso.Picasso;
import com.ss.android.a.AbManager;
import com.ss.android.account.Spipe;
import com.ss.android.account.model.SpipeCore;
import com.ss.android.common.AppContext;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.app.AppHooks;
import com.ss.android.common.app.AppHooks.InitHook;
import com.ss.android.common.app.permission.PermissionsManager;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.applog.NetUtil;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.location.LocationHelper;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.common.util.TtProperties;
import com.ss.android.image.FrescoUtils;
import com.ss.android.newmedia.d.DexDependAdapterImpl;
import com.ss.android.newmedia.d.UpdateUtilsImpl;
import com.ss.android.newmedia.h.PluginDependImpl;
import com.ss.android.newmedia.h.PluginInstaller;
import com.ss.android.newmedia.util.AppUtil;
import com.ss.android.push.window.oppo.OppoPushWindowManager;
import com.ss.android.update.UpdateHelper;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public abstract class BaseApplication extends AbsApplication implements
        com.bytedance.article.common.a.aa,
        HttpMonitorServerWorker,
        IMessageContext,
        InitHook,
        NetUtil.IAppParam,
        PluginInstaller.OnPluginInstallFinishListener {
    final class l$a extends BroadcastReceiver {
        private final BaseApplication a;

        l$a(BaseApplication arg1, byte arg2) {
            this(arg1);
        }

        private l$a(BaseApplication arg1) {
            this.a = arg1;
        }

        public final void onReceive(Context arg1, Intent arg2) {
        }
    }

    public static boolean b = true;
    protected final Handler c = new Handler();
    public CountDownLatch d;
    static boolean e = false;
    private String f;
    private String g;
    private String h;
    private int i;
    private String j = "local";
    private String k = null;
    private String l;
    private static String sDeviceId;
    private int n = -1;
    private int o = -1;
    private int p = -1;
    private String q = "";
    private volatile SharedPreferences r;
    private ThreadPoolExecutor s;
    private final AppConfig.a t;
    private final AppConfig.e u;
    private static boolean v = true;

    protected BaseApplication(String arg2, String arg3, String arg4) {
        this(arg2, arg3, arg4, 0);
    }

    public BaseApplication(String arg3, String arg4, String arg5, int arg6) {
        com.ss.android.l.c.a();
        com.ss.android.l.c.a();
        this.t = new AppConfig.a();
        this.u = new AppConfig.e();
        com.bytedance.ttstat.a.b(this);
        this.f = arg3;
        this.g = arg4;
        this.h = arg5;
        this.i = arg6;
        try {
            com.ss.android.l.c.c();
            com.ss.android.newmedia.h.a.setPluginDepend(PluginDependImpl.getInstance(((AppContext) this)));
            com.ss.android.l.c.c();
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    public final void A() {
        BaseApplication.l$a v0 = new BaseApplication.l$a(this, (byte) 0);
        IntentFilter v1 = new IntentFilter();
        v1.addAction("com.ss.android.newmedia.killApplication");
        try {
            this.registerReceiver(((BroadcastReceiver) v0), v1);
        } catch (Throwable v0_1) {
            Logger.throwExceptionInDebug(v0_1);
        }
    }

    public static void B() {
        JSONObject v1 = new JSONObject();
        MonitorHeaderInfoUtil.a(v1, AbsApplication.sApp.getApplicationContext());
        if (!android.support.design.a.isTextEmpty(AppLog.deviceId())) {
            try {
                v1.put("device_id", AppLog.deviceId());
            } catch (Exception v0) {
                v0.printStackTrace();
            }
        }

        if (v1.length() > 0) {
            Logger.i("headerInfo", v1.toString());
        }

        com.bytedance.framwork.core.monitor.c.a(AbsApplication.sApp.getApplicationContext(), v1, new com.bytedance.framwork.core.monitor.c.c$b());
        com.bytedance.article.common.a.g.a(false);
    }

    public final void onPluginInstallFinished() throws Throwable {
        if (Logger.debug()) {
            Logger.d("Plugin", "onPluginInstallFinished process" + ToolUtils.getCurProcessName(this));
        }

        try {
            if (PluginInstaller.isCronetPluginInstalled()) {
                com.ss.android.newmedia.g.a.a.a();
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        try {
            label_13:
            if (!PluginInstaller.isCommonPluginLiteInstalled()) {
                return;
            }

            if (ToolUtils.isMainProcess(this)) {
                try {
                    PushClassTest.testMainClass();
                } catch (Exception e) {
                    try {
                        PushClassLoader.hackClassLoader(this);
                    } catch (Exception ex) {

                    }
                } finally {
                    SsPushManager.inst().initPushOnApplication(this, ((IMessageContext) this));
                    this.E();
                    com.ss.android.newmedia.message.c v0_2 = com.ss.android.newmedia.message.c.a();
                    v0_2.j();
                    PluginInstaller.reportInstallResult(this, "com.bytedance.common.plugin.lite");
                    PluginInstaller.reportInstallResult(this, "com.bytedance.common.plugin.cronet");
                }
            }

            String v0_1 = ToolUtils.getCurProcessName(this);
            if (v0_1 == null) {
                return;
            }

            if (!v0_1.endsWith("push") && !v0_1.endsWith("pushservice")) {
                return;
            }

            if (!v0_1.endsWith("push")) {
                if (!v0_1.endsWith("pushservice")) {
                    return;
                }

                try {
                    SsPushManager.inst().initPushOnApplication(this, ((IMessageContext) this));
                    PushClassTest.testPushServiceClass();
                    return;
                } catch (Throwable v0) {
                    try {
                        v0.printStackTrace();
                        Process.killProcess(Process.myPid());
                        return;
                    } catch (Throwable tr) {
                        tr.printStackTrace();
                    }
                }
            }

            SsPushManager.inst().initPushOnApplication(this, ((IMessageContext) this));
            PushClassTest.testPushClass();
            return;
        } catch (Throwable v0) {
            try {
                v0.printStackTrace();
                Process.killProcess(Process.myPid());
                return;
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }
    }

    public final SharedPreferences D() {
        if (this.r == null) {
            synchronized (this) {
                if (this.r == null) {
                    this.r = this.getSharedPreferences("app_setting", 0);
                }
            }
        }

        return this.r;
    }

    private void E() {
        LocationHelper.a(new LocationHelper.c$a(this));
        LocationHelper.getInstance(this.getApplicationContext());
    }

    private void F() {
        android.support.design.a.w = "misc_config";
        android.support.design.a.u = com.ss.android.newmedia.download.a.g(this);
        android.support.design.a.v = new com.ss.android.common.download.g(this);
    }

    private void G() {
        try {
            com.bytedance.ttnet.cc.a(com.ss.android.newmedia.g.aa.getInstance());
        } catch (Throwable v0) {
            v0.printStackTrace();
        }

        com.bytedance.ttnet.cc.tryInitTTNet(this, this.t, this.u, com.ss.android.c.a.b());
    }

    private Account H() {
        int v2_1;
        Account v1 = null;
        try {
            AccountManager v0_1 = AccountManager.get(this);
            String v2 = this.getPackageName();
            String v3 = this.getString(this.getApplicationInfo().labelRes);
            if (TextUtils.isEmpty(((CharSequence) v3))) {
                return v1;
            }

            if (TextUtils.isEmpty(((CharSequence) v2))) {
                return v1;
            }

            Account[] v4 = v0_1.getAccountsByType(v2);
            int v5 = v4.length;
            v2_1 = 0;
            while (true) {
                label_15:
                if (v2_1 >= v5) {
                    return v1;
                }

                Account v0_2 = v4[v2_1];
                if (v0_2 != null) {
                    if (!v3.equals(v0_2.name)) {
                        ++v2_1;
                        continue;
                    }
                    return v0_2;
                }

                ++v2_1;
                continue;
            }
        } catch (Throwable v0) {
            Logger.ee("error to get account");
            v0.printStackTrace();
            return v1;
        }
    }

    private static void I() {
        try {
            new com.ss.android.sdk.shrink.b();
        } catch (Exception v0) {
        }
    }

    private void J() {
        int v0 = 0;
        try {
            if (!new File(Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + this.getPackageName() + "/cache/" + "debug.flag").exists()) {
            } else {
                v0 = 1;
            }
        } catch (Exception v1) {
        }
        if (v0 != 0) {
            Logger.enableDebug();
            LiteConstants.setLogLevel(2);
        }
    }

    private void K() {
        String v0_3;
        ZipFile v1 = null;
        String v2 = null;
        if (!"2345".equals(this.j)) {
            return;
        }

        String v4 = "META-INF/channel_";
        try {
            v1 = new ZipFile(this.getApplicationInfo().sourceDir);
            Enumeration<? extends ZipEntry> v5 = v1.entries();
            do {
                if (v5.hasMoreElements()) {
                    v0_3 = ToolUtils.e(v5.nextElement().getName());
                    if (!v0_3.startsWith(v4)) {
                        continue;
                    }
                    String[] v0_4 = v0_3.split("_", 4);
                    if (v0_4 != null && v0_4.length >= 3) {
                        v2 = v0_4[2];
                    }

                    if (v2 == null) {
                        return;
                    }

                    if (v2.length() <= 0) {
                        return;
                    }

                    if (v2.length() >= 50) {
                        return;
                    }

                    int v4_1 = v2.length();
                    int v0_5 = 1;
                    int v1_1;
                    for (v1_1 = 0; v1_1 < v4_1; ++v1_1) {
                        int v5_1 = v2.charAt(v1_1);
                        if ((v5_1 < 97 || v5_1 > 122) && (v5_1 < 65 || v5_1 > 90) && (v5_1 < 48 || v5_1 > 57) && v5_1 != 45) {
                            v0_5 = 0;
                            break;
                        }
                    }

                    if (v0_5 == 0) {
                        return;
                    }

                    this.k = this.j + "_" + v2;
                    return;
                }

                break;
            } while (true);

        } catch (Exception v0_1) {
            try {
                v1.close();
            } catch (Exception ex) {
            }
        }


    }

    private void L() {
        try {
            this.loadDepend();
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    private String M() {
        String v0_1;
        try {
            v0_1 = System.getProperty("http.agent");
            if (android.support.design.a.isTextEmpty(v0_1)) {
                return v0_1;
            }

            String v1 = this.getVersion();
            if (android.support.design.a.isTextEmpty(v1)) {
                return v0_1;
            }

            v0_1 = v0_1 + " NewsArticle/" + v1;
        } catch (Throwable v0) {
            v0_1 = "NewsArticle/xxx";
        }

        return v0_1;
    }

    public static void a(HttpRequestInfo httpRequestInfo, JSONObject jo) {
        if (httpRequestInfo != null) {
            try {
                jo.put("requestStart", httpRequestInfo.requestStartTs);
                jo.put("responseBack", httpRequestInfo.responseBack);
                jo.put("completeReadResponse", httpRequestInfo.fetchResponseTs);
                jo.put("requestEnd", httpRequestInfo.requestEnd);
                jo.put("recycleCount", httpRequestInfo.recycleCount);
                jo.put("timing_dns", httpRequestInfo.timingDns);
                jo.put("timing_connect", httpRequestInfo.timingConnect);
                jo.put("timing_ssl", httpRequestInfo.timingSsl);
                jo.put("timing_send", httpRequestInfo.timingSend);
                jo.put("timing_waiting", httpRequestInfo.timingWaiting);
                jo.put("timing_receive", httpRequestInfo.timingReceive);
                jo.put("timing_total", httpRequestInfo.timingTotal);
                jo.put("timing_isSocketReused", httpRequestInfo.timingIsSocketReused);
                jo.put("timing_totalSendBytes", httpRequestInfo.timingTotalSendBytes);
                jo.put("timing_totalReceivedBytes", httpRequestInfo.timingTotalReceivedBytes);
                jo.put("timing_remoteIP", httpRequestInfo.timingRemoteIP);
                jo.put("trace_cache", "");
                jo.put("download", httpRequestInfo.download);
            } catch (JSONException v0) {
                v0.printStackTrace();
            }
        }
    }

    static Account a(BaseApplication arg1) {
        return arg1.H();
    }

    private static String a(int arg3, String arg4) {
        try {
            StringBuilder v0_1 = new StringBuilder();
            while (arg3 > 0) {
                int v1 = arg3 % 10;
                arg3 /= 10;
                v0_1.insert(0, v1);
                if (arg3 <= 0) {
                    continue;
                }

                v0_1.insert(0, ".");
            }

            return v0_1.toString();
        } catch (Throwable v0) {
        }

        return arg4;
    }

    public static void a(boolean arg1) {
        BaseApplication.v = arg1;
        BaseApplication.e = false;
    }

    public final String a() {
        return this.l;
    }

    public final void tryInit(Context arg3) {
        if (Logger.debug()) {
            Logger.d("Non-MessageProcess", "BaseAppData.inst().tryInit");
        }

        BaseAppData.inst().b(arg3);
    }

    public final void getSSIDs(Context context, Map arg4) {
        if (Logger.debug()) {
            Logger.d("NetUtil", "getSSIDs");
        }

        if (context != null) {
            if (Logger.debug()) {
                Logger.d("PushService", "getSSIDs start");
            }

            try {
                String v0_1 = android.support.design.a.a(context, 1);
                if (android.support.design.a.isTextEmpty(v0_1)) {
                    return;
                }

                android.support.design.a.a(v0_1, arg4);
            } catch (Exception v0) {
            }
        }
    }

    public final int b() {
        return this.n;
    }

    public final int c() {
        return this.o;
    }

    public final int d() {
        return this.p;
    }

    public void e() {
        AbManager.a(MediaAppData.provide().lastVersionCode);
        AbManager.getInstance(((AppContext) this));
        if (BaseApplication.b) {
            com.ss.android.l.c.c();
            try {
                int v0 = this.getSharedPreferences("app_setting", 0).getInt("location_gaode_asynchronous_switch", 1);


                if (v0 == 0) {
                    LocationHelper.getInstance(this);
                } else {
                    new t(this).start();
                }

                com.ss.android.l.c.c();
            } catch (Throwable v1) {
            }
        }
    }

    public String getAbClient() {
        return null;
    }

    public long getAbFlag() {
        return 0;
    }

    public int getAid() {
        return this.i;
    }

    public String getAppName() {
        return this.f;
    }

    public Context getBaseContext() {
        return super.getBaseContext();
    }

    public Context getContext() {
        return this;
    }

    public String getTweakedChannel() {
        return this.k != null ? this.k : this.j;
    }

    public String getVersion() {
        return this.l;
    }

    public int getVersionCode() {
        return this.n;
    }

    public String getAbVersion() {
        return null;
    }

    public void handleOpenUrl(String openUrl) {
        Log.d("LocalHttpd", "handleOpenUrl() called with: openUrl = [" + openUrl + "]");
        if (!TextUtils.isEmpty(openUrl)) {
            try {
                JSONObject jo = new JSONObject();
                jo.put("url", openUrl);
                MobClickCombiner.onEvent(this, "local_http_server", "handle_open_url", -1, -1, jo);
            } catch (JSONException e) {
                e.printStackTrace();
            }

            this.c.post(new p(this, openUrl));
        }
    }

    public String getAbGroup() {
        return null;
    }

    public String getAbFeature() {
        return null;
    }

    private static void k() {
        AlertDialog.setNightMode(new s());
        PermissionsManager.a(new PermissionsManager.a());
    }

    public void loadDepend() {
        com.bytedance.article.b.a.g v1_6;
        m v1_3;
        com.bytedance.article.b.a.q v1_2;
        Object v0_1;
        GsonDependManager gsonDependManager;
        try {
            com.ss.android.newmedia.d.c.a();
            gsonDependManager = GsonDependManager.getInstance();
            if (gsonDependManager.jsonTransformer != null) {
            } else if (TextUtils.isEmpty("com.ss.android.article.base.app.m")) {
            } else {
                Object instance = Class.forName("com.ss.android.article.base.app.GsonTransformer").newInstance();
                if (instance instanceof JsonTransformer) {
                    gsonDependManager.jsonTransformer = ((JsonTransformer) instance);
                }
            }
        } catch (Throwable throwable) {
            try {
                Log.d("DexParty", "load GsonDependManager exception: " + throwable);
                if (Logger.debug()) {
                    throw new IllegalArgumentException(throwable);
                }
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }


        try {
            if (android.support.design.a.sUmengAgent != null) {
            } else if (TextUtils.isEmpty("u.aly.UmengAgent")) {
            } else {
                Object instance = Class.forName("u.aly.UmengAgent").newInstance();
                if (instance instanceof MobClickCombiner.IUmengAgent) {
                    android.support.design.a.sUmengAgent = ((MobClickCombiner.IUmengAgent) instance);
                    MobClickCombiner.setUmengAgent(((MobClickCombiner.IUmengAgent) instance));
                }
            }
        } catch (Throwable ex) {
            try {
                Log.d("DexParty", "load IUmengAgent exception: " + ex);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }

        try {
            DexDependAdapterImpl.loadDexDependAdapter(this, "2504490989");
            com.bytedance.article.b.a.a v1_1 = com.bytedance.article.b.a.a.a();
            if (v1_1.a != null) {
            } else {
                LiteProxy liteProxy = LiteProxy.inst();
                if (liteProxy instanceof IAliPay) {
                    v1_1.a = ((IAliPay) liteProxy);
                }
            }
        } catch (Throwable ex) {
            try {
                Log.d("DexParty", "load AliPayAdapter exception: " + ex);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }

        try {
            v1_2 = com.bytedance.article.b.a.q.a();
            if (v1_2.a != null) {
            } else if (TextUtils.isEmpty("com.ss.android.dex.party.a.a")) {
            } else {
                Object instance = Class.forName("com.ss.android.dex.party.a.a").newInstance();
                if (instance instanceof com.bytedance.article.b.h) {
                    v1_2.a = ((com.bytedance.article.b.h) instance);
                }
            }
        } catch (Throwable ex) {
            try {
                Log.d("DexParty", "load Zip4JDependManager exception: " + ex);
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }

        try {
            label_46:
            v1_3 = com.bytedance.article.b.a.m.a();
            if (v1_3.a != null) {
            } else if (TextUtils.isEmpty("com.ss.android.dex.party.httpresponsecache.HttpResponseCacheDependAdapter")) {
            } else {
                v0_1 = Class.forName("com.ss.android.dex.party.httpresponsecache.HttpResponseCacheDependAdapter").newInstance();
                if (v0_1 instanceof com.bytedance.article.b.f) {
                    v1_3.a = ((com.bytedance.article.b.f) v0_1);
                }
            }
        } catch (Throwable ex) {
            try {
                Log.d("DexParty", "load HttpResponseCacheDependManager exception: " + ex);
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }

        try {
            com.bytedance.article.b.a.e v1_4 = com.bytedance.article.b.a.e.a();
            if (v1_4.a != null) {
            } else if (TextUtils.isEmpty("com.ss.android.dex.party.commodity4jingdong.CommodityJDDependAdapter")) {
            } else {
                v0_1 = Class.forName("com.ss.android.dex.party.commodity4jingdong.CommodityJDDependAdapter").newInstance();
                if (!(v0_1 instanceof com.bytedance.article.b.bb)) {
                } else {
                    v1_4.a = (com.bytedance.article.b.bb) v0_1;
                }
            }
        } catch (Throwable ex) {
            try {
                Log.d("DexParty", "load CommodityJDDependManager exception: " + ex);
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }

        try {
            com.bytedance.article.b.a.c v1_5 = com.bytedance.article.b.a.c.a();
            if (v1_5.a != null) {
            } else if (TextUtils.isEmpty("com.ss.android.dex.party.commodity4baichuan.CommodityBCDependAdapter")) {
            } else {
                v0_1 = Class.forName("com.ss.android.dex.party.commodity4baichuan.CommodityBCDependAdapter").newInstance();
                if (!(v0_1 instanceof com.bytedance.article.b.aa)) {
                } else {
                    v1_5.a = (DependProvider<com.bytedance.article.b.a.c>) v0_1;
                }
            }
        } catch (Throwable v0) {
            try {
                Log.d("DexParty", "load CommodityBCDependManager exception: " + v0);
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }

        try {
            v1_6 = com.bytedance.article.b.a.g.a();
            if (v1_6.a != null) {
            } else if (TextUtils.isEmpty("com.ss.android.ad.commodity4kepler.KeplerAdProcessAdapter")) {
            } else {
                v0_1 = Class.forName("com.ss.android.ad.commodity4kepler.KeplerAdProcessAdapter").newInstance();
                if (!(v0_1 instanceof com.bytedance.article.b.c)) {
                } else {
                    v1_6.a = ((com.bytedance.article.b.c) v0_1);
                }
            }
        } catch (Throwable v0) {
            Log.d("DexParty", "load CommodityKeplerDependManager exception: " + v0);
        }
        try {
            com.bytedance.article.b.a.o.a().b();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

    }

    public void m() {
        this.G();
        this.o();
        com.ss.android.l.c.c();
        com.bytedance.ttnet.a.AppConfig.getInstance(this);
        com.ss.android.l.c.c();
        BaseApplication.I();
        com.ss.android.l.c.c();
        this.F();
        BaseApplication.k();
        com.ss.android.l.c.c();
        this.E();
        com.ss.android.l.c.c();
        try {
            com.ss.android.newmedia.d.e.a();
            UpdateUtilsImpl.a();
            com.ss.android.newmedia.d.a.a();
            com.ss.android.newmedia.d.b.a();
        } catch (Throwable v0) {
        }

        com.ss.android.l.c.c();
    }

    public void n() {
        com.ss.android.newmedia.message.c.k.countDown();
        new com.ss.android.newmedia.o(this).start();
    }

    public void o() {
        com.ss.android.newmedia.message.c.a();
        com.ss.android.newmedia.feedback.a.a();
        com.bytedance.article.common.a.e.a();
        com.ss.android.account.cc.a();
        com.ss.android.action.bb.a();
    }

    public void onCreate() {
        String v0_4;
        int v0_3;
        PackageInfo v3;
        PackageInfo v1 = null;
        int v2 = 3;
        com.ss.android.l.c.c();
        ToolUtils.a(":pushservice");
        try {
            Executor v0_1 = AsyncTask.THREAD_POOL_EXECUTOR;
            if (!(v0_1 instanceof ThreadPoolExecutor)) {
            } else {
                ((ThreadPoolExecutor) v0_1).setCorePoolSize(3);
                ((ThreadPoolExecutor) v0_1).setMaximumPoolSize(5);
            }
        } catch (Throwable v0) {
            v0.printStackTrace();
        }

        label_15:
        com.bytedance.ttstat.a.f(this);
        boolean v11 = ToolUtils.isMainProcess(this);
        String v12 = ToolUtils.getCurProcessName(this.getApplicationContext());
        MessageConstants.setIMessageDepend(com.ss.android.newmedia.message.g.a());
        SsPushManager.inst().initPushOnApplication(this, this);
        OpenUrlReceiverUtil.setHttpMonitorServerWorker(this);
        if (v11) {
            this.L();
            OppoPushWindowManager.a(this, new com.ss.android.push.window.oppo.a());
        } else {
            if (!v12.endsWith(":pushservice") && !v12.endsWith(":push") && !v12.endsWith(":remote") && !v12.endsWith(":ad")) {
//                goto label_29;
            } else {
                this.L();
            }
        }

        label_29:
        BaseApplication.sApp = ((AbsApplication) this);
        if (BaseApplication.b) {
            this.J();
        } else {
            this.A();
        }

        com.ss.android.l.c.c();
        com.bytedance.ttstat.a.b(this, v11);
        super.onCreate();
        com.ss.android.l.c.c();
        com.bytedance.ttstat.a.a(this, v11);
        System.setProperty("http.keepAlive", "false");
        if (Logger.debug()) {
            Logger.d("Process", " pid = " + Process.myPid() + " " + v12);
        }

        this.initDeviceId();
        try {
            v3 = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
        } catch (Exception v0_2) {
            v0_2.printStackTrace();
            v3 = v1;
        }

        try {
            this.l = (String) android.support.design.a.c(this.getApplicationContext(), "SS_VERSION_NAME");
        } catch (Exception v0_2) {
        }

        if ((android.support.design.a.isTextEmpty(this.l)) && v3 != null) {
            this.l = v3.versionName;
        }

        try {
            this.n = android.support.design.a.d(this.getApplicationContext(), "SS_VERSION_CODE");
        } catch (Exception v0_2) {
        }

        if (this.n == -1 || this.n == 0) {
            v0_3 = v3 != null ? v3.versionCode : 1;
            this.n = v0_3;
        }

        try {
            this.o = android.support.design.a.d(this.getApplicationContext(), "UPDATE_VERSION_CODE");
        } catch (Exception v0_2) {
        }

        if (v3 != null) {
            this.p = v3.versionCode;
            this.q = v3.versionName;
        }

        if (BaseApplication.sDeviceId == null) {
            BaseApplication.sDeviceId = "";
        }

        if (this.l == null) {
            this.l = "-1";
        }

        try {
            v0_4 = TtProperties.getInstance(this).getString("meta_umeng_channel", "");
        } catch (Exception v0_2) {
            v0_4 = null;
        }

        if (v0_4 != null && v0_4.length() > 0) {
            this.j = v0_4;
        }

        this.k = this.j;
        this.K();
        if (!ToolUtils.isMainProcess(this)) {
            com.bytedance.ttnet.cc.a(this.M());
        }

        com.bytedance.common.utility.e.a(new com.bytedance.article.common.network.a());
        MobClickCombiner.setUmengChannel(this.k);
        MonitorHeaderInfoUtil.a(this.i);
        MonitorHeaderInfoUtil.a(this.k);
        v0_3 = this.o / 10;
        if (v0_3 > this.p) {
            this.q = BaseApplication.a(v0_3, this.q);
            this.p = v0_3;
        }

        MobClickCombiner.setVersionInfo(this.q, this.p);
        com.ss.android.l.c.c();
        Spipe.a(this);
        com.ss.android.l.c.c();
        this.G();
        com.ss.android.l.c.c();
        SpipeCore.setAppId(this.g);
        AppLog.g();
        AppLog.g(this.k);
        AppLog.b(this.i);
        AppLog.a(((AppContext) this));
        Account v0_5 = this.H();
        if (v0_5 != null) {
            AppLog.a(this, v0_5);
        }

        AppLog.a(new com.ss.android.f.a.b());
        try {
            v0_4 = TtProperties.getInstance(this).getString("release_build", "");
            AppLog.h(v0_4);
            MonitorHeaderInfoUtil.b(v0_4);
        } catch (Exception v0_2) {
        }

        try {
            AppLog.a(com.ss.android.common.applog.c.a());
        } catch (Exception v0_2) {
        }

        if (ToolUtils.isMainProcess(this)) {
            com.ss.android.newmedia.message.c.a().k();
            AppLog.H();
            AppUtil.setContext(this);
            AppHooks.setInitHook(((InitHook) this));
            com.ss.android.newmedia.a.d v0_6 = com.ss.android.newmedia.a.d.a;
            AppLog.a("log.snssdk.com");
            AppLog.b("mon.snssdk.com");
            AppLog.c("ib.snssdk.com");
            AppLog.a(new com.ss.android.common.applog.AppLog.AppLog$f(this));
            ComponentsManifest.addComponent(com.ss.android.aa.class, new n());
            AppHooks.setActivityHook(((AppHooks.ActivityLifeCycleHook) v0_6));
            AppHooks.setActivityResultHook(((AppHooks.ActivityResultHook) v0_6));
            AppHooks.setAppBackgroundHook(((AppHooks.AppBackgroundHook) v0_6));
            AppHooks.getAppBackgroundHook(((AppHooks.AppStartMonitorHook) v0_6));
            UpdateHelper.ensureUpdateHelper(this, ((UpdateHelper.c) v0_6));
            AppLog.a(((com.ss.android.common.applog.AppLog.g) v0_6));
            AppLog.a(((com.ss.android.common.applog.AppLog.e) v0_6));
        } else {
            AppLog.b(this);
        }

        if (!BaseApplication.b) {
            this.J();
        }

        com.ss.android.l.c.c();
        if ((BaseApplication.b) && (v11)) {
            boolean v0_7 = Runtime.getRuntime().availableProcessors() >= 4 ? true : false;
            if (!v0_7) {
                v2 = 2;
            }

            this.s = new ThreadPoolExecutor(v2, v2, 5, TimeUnit.SECONDS, new LinkedBlockingQueue(), new u());
            this.s.allowCoreThreadTimeOut(true);
            this.d = new CountDownLatch(1);
            com.ss.android.newmedia.k.b();
            this.s.submit(new v(this));
            this.s.submit(new w(this));
            Logger.i("AsyncLoad", "asyncLoadRes = " + v0_7);
        }

        com.ss.android.l.c.c();
        if (!v11 && (PluginUtil.isWorkProcess(v12))) {
            PluginInstaller.installPlugins(this, ProcessType.WORK, this);
        }

        com.ss.android.l.c.c();
        try {
            Reflect v0_8 = Reflect.onClass(Class.forName("android.app.ActivityThread")).call("currentActivityThread");
            if (v0_8 == null) {
//                goto label_278;
            } else {
                Object activityThread$H = v0_8.get("mH", new Class[]{Class.forName("android.app.ActivityThread$H")}).target;
                if (activityThread$H == null) {
//                goto label_278;
                } else {
                    Reflect v2_1 = Reflect.on(activityThread$H);
                    final Handler handler = (Handler) activityThread$H;
                    final Handler.Callback callback = (Handler.Callback) v2_1.get("mCallback", new Class[]{Handler.Callback.class}).target;

                    v2_1.set("mCallback",
                            new Handler.Callback() {

                                private boolean a() {
                                    try {
                                        if (Class.forName("com.lody.virtual.client.local.VActivityManager") == null) {
                                            return false;
                                        }
                                    } catch (ClassNotFoundException v0_1) {
                                        Logger.i("VirtualAppException", "Not virtual app exception.");
                                        return false;
                                    }

                                    boolean v0_2 = true;
                                    return v0_2;
                                }

                                private boolean a(Throwable arg2) {
                                    try {
                                        if (!"android.app.RemoteServiceException".equals(arg2.getClass().getName())) {
                                            return false;
                                        }

                                        if (!arg2.getMessage().trim().startsWith("Bad notification")) {
                                            return false;
                                        }
                                    } catch (Throwable v0) {
                                        v0.printStackTrace();
                                        return false;
                                    }

                                    boolean v0_1 = true;
                                    return v0_1;
                                }

                                private boolean b(Throwable arg1) {
                                    boolean v0_1;
                                    try {
                                        v0_1 = PushClassLoader.isMatchPushClassNotFound(arg1);
                                    } catch (Throwable v0) {
                                        v0.printStackTrace();
                                        v0_1 = false;
                                    }

                                    return v0_1;
                                }

                                private boolean c(Throwable arg2) {
                                    try {
                                        if (!"java.lang.SecurityException".equals(arg2.getClass().getName())) {
                                            return false;
                                        }

                                        if (arg2.getMessage().trim().indexOf("cannot kill pkg:") == -1) {
                                            return false;
                                        }
                                    } catch (Throwable v0) {
                                        v0.printStackTrace();
                                        return false;
                                    }

                                    boolean v0_1 = true;
                                    return v0_1;
                                }

                                public final boolean handleMessage(Message arg4) {
                                    boolean v0 = false;
                                    if (arg4 == null) {
                                        if (callback == null) {
                                            return v0;
                                        }

                                        return callback.handleMessage(arg4);
                                    }

                                    try {
                                        if (callback != null) {
                                            v0 = callback.handleMessage(arg4);
                                        }

                                        if (v0) {
                                            return true;
                                        }

                                        if (handler != null) {
                                            handler.handleMessage(arg4);
                                        }
                                    } catch (Throwable v0_1) {
                                        if (a()) {
                                            return true;
                                        } else if (a(v0_1)) {
                                            return true;
                                        } else if (b(v0_1)) {
                                            return true;
                                        } else if (c(v0_1)) {
                                            return true;
                                        } else {
                                            throw v0_1;
                                        }
                                    }

                                    return true;
                                }
                            });
                }
            }
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
        com.ss.android.l.c.c();
        if (ToolUtils.isMessageProcess(this)) {
            if (Logger.debug()) {
                Logger.d("MessageProcess", v12 + " start");
            }

            android.support.design.a.j(this);
            NetUtil.a(((NetUtil.IAppParam) this));
            return;
        }

        com.ss.android.l.c.c();
        if (!v11) {
            if (!Logger.debug()) {
                return;
            }

            Logger.d("Process", v12 + " no need to init");
            return;
        }

        MonitorHeaderInfoUtil.a(this);
        com.ss.android.l.c.c();
        com.ss.android.l.c.c();
        if (BaseApplication.b) {
            this.o();
            PluginInstaller.installPlugins(this, ProcessType.MAIN, this);
            com.ss.android.newmedia.message.c.a().b();
            com.ss.android.l.c.c();
            com.bytedance.ttstat.a.g(this);
            com.ss.android.l.c.c();
            return;
        }

        this.o();
        PluginInstaller.installPlugins(this, ProcessType.MAIN, this);
        try {
            com.ss.android.newmedia.message.c.a();
            this.getApplicationContext();
            com.ss.android.newmedia.message.c.i();
        } catch (Exception v0_2) {
        }

        BaseApplication.I();
        this.F();
        BaseApplication.k();
        try {
            v0_3 = this.getSharedPreferences("app_setting", 0).getInt("location_gaode_asynchronous_switch", 1);
        } catch (Throwable v0) {
            v0_3 = 0;
        }

        if (v0_3 == 0) {
            LocationHelper.getInstance(this);
        } else {
            new com.ss.android.newmedia.m(this).start();
        }

        this.y();
        new com.ss.android.newmedia.r(this, "Application-AsyncInit").start();
        com.ss.android.newmedia.message.c.a().b();
        try {
            com.ss.android.newmedia.d.e.a();
            com.ss.android.newmedia.d.c.a();
            UpdateUtilsImpl.a();
            com.ss.android.newmedia.d.a.a();
            com.ss.android.newmedia.d.b.a();
        } catch (Throwable v0) {
        }

        new com.ss.android.account.dd(this).start();
        com.bytedance.ttstat.a.g(((Application) this));
        label_360:
        com.bytedance.ttstat.a.g(((Application) this));
        com.ss.android.l.c.c();
    }

    public void onLowMemory() {
        super.onLowMemory();
        Logger.d("Application", "onLowMemory");
        com.bytedance.article.common.a.g.serviceMonitor("on_low_mem", 0, null);
    }

    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        Logger.d("Application", "onTrimMemory level-" + level);
        if (ToolUtils.isMainProcess(this)) {
            com.bytedance.article.common.a.g.serviceMonitor("on_trim_mem", level, null);
            if (FrescoUtils.isInitialized()) {
                int trimRatio = 4;
                if (BaseAppData.isInitialized() && BaseAppData.inst().isAppForeground()) {
                    if (level <= 5) {
                        trimRatio = 1;
                    } else if (level <= 10) {
                        trimRatio = 2;
                    } else if (level > 15) {
                        trimRatio = 100;
                    }
                    Picasso.with(this).trimCritical(trimRatio);
                } else {
                    if (level > 20) {
                        trimRatio = level <= 40 ? 8 : 100;
                    }
                    Picasso.with(this).trimGentle(trimRatio);
                }
            }
        }
    }

    public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
        if (Logger.debug()) {
            Logger.d("AdService", "openOrCreateDatabase name = " + name);
        }
        String curProcessName = ToolUtils.getCurProcessName(this);
        if (!android.support.design.a.isTextEmpty(curProcessName)
                && !android.support.design.a.isTextEmpty(name)
                && (curProcessName.endsWith(":ad"))
                && Build.VERSION.SDK_INT < 19) {
            name = "ad_" + name;
            if (Logger.debug()) {
                Logger.d("AdService", "openOrCreateDatabase new name = " + name);
            }
        }
        return super.openOrCreateDatabase(name, mode, factory);
    }

    public final String getStringAppName() {
        return this.getString(com.ss.android.article.browser.R.string.app_name);
    }

    public final String getFeedbackAppKey() {
        return this.h;
    }

    public final String getChannel() {
        return this.j;
    }

    public final String getDeviceId() {
        return BaseApplication.sDeviceId;
    }

    public final int getUpdateVersionCode() {
        return this.o;
    }

    public final int getManifestVersion() {
        return this.p;
    }

    public final String getAppVersion() {
        return this.q;
    }

    public final void y() {
        try {
            if (!BaseAppData.i(this.getApplicationContext())
                    && (BaseAppData.o(this.getApplicationContext()))) {
                BaseAppData.b(this.getApplicationContext(), false);
            }

            if (BaseApplication.v) {
                return;
            }

            BaseAppData.a(this.getApplicationContext(), true);
        } catch (Exception v0) {
        }
    }

    @SuppressLint("MissingPermission")
    public final void initDeviceId() {
        try {
            BaseApplication.sDeviceId = ((TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        } catch (Exception exception) {
        }
    }
}

